/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package TimeRecording.business;

import static TimeRecording.business.DaisyChainUtilities.*;

import TimeRecording.enums.PartOfDay;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author david
 */
public class SpendExplanation {

    private final static SimpleDateFormat DATE_FORMATTER =
            new SimpleDateFormat("dd-MMM-yyyy  ");

    private final static NumberFormat NUMBER_FORMATTER =
            new DecimalFormat("##0.00");

    private final static String HEADER = "\n" +
            "  Date         Day        Day Part   Hours   Total\n" +
            "  ==========   ========   ========   =====   =====\n";

    private StringBuffer buffer;
    private double totalSpend;

    public void start() {
        buffer = new StringBuffer(HEADER);
        totalSpend = 0.0;
    }

    public void add(Date date, PartOfDay partOfDay, double spend) {
        totalSpend += spend;
        buffer.append("  ");
        buffer.append(DATE_FORMATTER.format(date));
        buffer.append(padString(getDay(date), 11));
        buffer.append(padString(getPartOfDay(partOfDay), 11));
        buffer.append(padString(NUMBER_FORMATTER.format(spend), 8));
        buffer.append(NUMBER_FORMATTER.format(totalSpend));
        buffer.append("\n");
    }

    public String getExplanation() {
        return buffer.toString();
    }
}
